#!/usr/bin/env python39
# -*- coding:utf-8 -*-
from copyheaders import headers_raw_to_dict
from requests_html import HTMLSession

str = b'''
cookie: _ma_tk=dt40rinds240opegfplwkap4qyl7xtmy; UM_distinctid=1800bb2107cec1-0410dbc1fed3c6-1f343371-13c680-1800bb2107de81; CNZZDATA1000010102=1224691108-1649459309-https%253A%252F%252Fwww.huanqiu.com%252F%7C1649459309; REPORT_UID_=mwEH6CY5LzzbsrjzzfzAJmhrwjAq7N8i; Hm_lvt_1fc983b4c305d209e7e05d96e713939f=1649463661,1649464802; Hm_lpvt_1fc983b4c305d209e7e05d96e713939f=1649465492
referer: https://china.huanqiu.com/
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36
'''


class World_Wide_Web:
    def __init__(self):
        self.session = HTMLSession()
        self.headers = headers_raw_to_dict(str)
        self.url = 'https://china.huanqiu.com/api/list?node=%22/e3pmh1nnq/e3pmh1obd%22,%22/e3pmh1nnq/e3pn61c2g%22,%22/e3pmh1nnq/e3pn6eiep%22,%22/e3pmh1nnq/e3pra70uk%22,%22/e3pmh1nnq/e5anm31jb%22,%22/e3pmh1nnq/e7tl4e309%22&offset={}&limit=20'

    def run(self, url):
        try:
            r = self.session.get(url=url, headers=self.headers)
            print(r.status_code, r.encoding)
            element_data = r.json()['list']
            if element_data is not None:
                for element in element_data:
                    print(element)
        except Exception as e:
            print('Error:', e)

    def main(self):
        urls_list = [self.url.format(page) for page in range(0, 11)]
        for url in urls_list:
            self.run(url)


if __name__ == '__main__':
    w = World_Wide_Web()
    w.main()
